package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.example.domain.Book;
import com.example.jms.SendJMS;
import com.example.service.BookService;


@Controller
@RequestMapping("/secode")
public class SecondController {
   private static Logger logger=LoggerFactory.getLogger(SecondController.class);
   @Autowired
	private BookService bs;
	@Value("${ipbatton}")
	private String ipbatton;
   @RequestMapping("/get")
	public ModelAndView secode(@RequestParam("bookid") String bookid ,ModelAndView review){
	   
	   Book book=bs.get(bookid);
	   review.setViewName("exjsp/myfirst");
	   review.addObject("page", book);
	   
	   logger.info("失败了:"+ipbatton);
		return review;
	}
   @Autowired
   SendJMS send;
   @RequestMapping("/send")
   public void send(){
	   int a=0;
		for(int i=0;i<10001;i++){
			Map<String ,Object> map=new HashMap<String,Object>();
			map.put("mobileid", "ddd"+i);
			a++;
			send.send("testexample", map);
		}
		logger.info("a="+a);
   }
   
   @RequestMapping("/update")
	public ModelAndView update(@RequestParam("id") String bookid ,@RequestParam("name") String bookname ,ModelAndView review){
	   
	   Book book=bs.get(bookid);
	   book.setName(bookname);
	   bs.updateBook(book);
	   review.setViewName("exjsp/myfirst");
	   review.addObject("page", book);
	   
	   logger.info("失败了:"+ipbatton);
		return review;
	}
}
